package demo1;

// 不同名的成员变量
/*class Base {
    public int a;
    public int b;
}


class Derived extends Base  {
    public int c;

    public void method() {
        a = 1;
        b = 2;
        c = 3;
    }
}*/

/*// 同名的成员变量
class Base {
    public int a = 9;
    public int b = 99;
}


class Derived extends Base  {
    public int a = 88;
    public void method() {
        //优先看子类是否有当前成员变量 —— 就近原则
        System.out.println("a: "+ a);
        System.out.println("b: "+ b);
    }
}*/


class Base {
    public int a = 99;
    public void method() {
        System.out.println("B::method()");
    }
}

class Derived extends Base {

    public int a = 199;

    public void method() {
        System.out.println("Derived::method()");
    }

    public void method2() {
        System.out.println("Derived::method2()");
    }

    public void test() {
        super.method();
        method2();
        System.out.println("===================");
        System.out.println(a);
        System.out.println(this.a);
        System.out.println(super.a);
    }
}


public class Test2 {
    public static void main(String[] args) {
        Derived derived = new Derived();
        //derived.method();
        //derived.method2();
        derived.test();
    }
}
